package com.itqf.mybatis;

import com.itqf.mapper.AuthorMapper;
import com.itqf.pojo.Author;
import com.itqf.pojo.Blog;
import com.itqf.utils.SqlSessionUtils;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

/**
 * projectName: mybatisgp8
 *
 * @author: 赵伟风
 * time: 2021/7/30 15:06
 * description:多表集合查询,查询作者和blog
 */
public class ListQuery {

    public static void main(String[] args) {


        SqlSession sqlSession = SqlSessionUtils.openSession();

        AuthorMapper mapper = sqlSession.getMapper(AuthorMapper.class);

        List<Author> authors = mapper.queryAll();

        for (Author author : authors) {
            System.out.println("作者:"+author.getaName());
            System.out.println("作者的blogs:");
            for (Blog blog : author.getBlogs()) {
                System.out.println("blogName:"+blog.getbTitle());
            }
            System.out.println("----------------------");
        }


        sqlSession.close();

    }

}
